<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>样式绑定内联练习</title>
    <script src="../../js/vue.js"></script>
    <style>
        div {
            height: 20px;
        }
        #app{
            margin: 5rem auto;
            width: 10%;
        }
    </style>
</head>

<body>
    <div id="app">
        <div :style="{backgroundColor:bg_color1,width:div_long1+'rem'}">
            <div :style="{backgroundColor:bg_color2,width:count+'rem'}">

            </div>
        </div>

        <p>得票数: {{count}}</p>
        <p>
            <button v-on:click="add">投票</button>
            <button v-on:click="jian">撤回</button>
        </p>
    </div>
    <script>
        var v_app = new Vue({
            el: "#app",
            data: {
                count: 0,
                bg_color1: "gray",
                bg_color2: "red",
                div_long1: 10,
            },
            methods: {
                add() {
                    if (this.count < this.div_long1) {
                        this.count++;
                    }
                },
                jian() {
                    if (this.count > 0) {
                        this.count--;
                    }
                }
            }
        });
    </script>
</body>

</html>